<HEAD>
  <SCRIPT SRC="../ganja.js"></SCRIPT>
</HEAD>
<BODY><SCRIPT>
// Create a Clifford Algebra with 2,0,1 metric. 
Algebra(2,0,1,()=>{
  
  // The identities we already established.
  var point = (x,y)=>1e12-x*1e02+y*1e01,    
      line  = (a,b,c)=>a*1e1+b*1e2+c*1e0;
      
  // Distances and angles
  var dist_pp = (X,Y)=>(X&Y).Length,
      dist_pl = (P,l)=>(P.Normalized^l.Normalized).e012,
      angle   = (x,y)=>Math.acos(x.Normalized<<y.Normalized);

  var A=()=>point(-1,0.5*Math.sin(0.0005*performance.now())),  // expression on time
      B=point(-1,-1), C=point(1,-1); 
  
  // Define some algebraic expressions as functions of these points.
  var AB=()=>B&A, BC =()=>C&B, CA=()=>C&A;

  // Distances between points as functions that return labels (strings);
  var AtoB   =()=>dist_pp(A,B).toFixed(3),  
      BtoC   =()=>dist_pp(C,B).toFixed(3),     
      CtoA   =()=>dist_pp(C,A).toFixed(3);

  // Angles between lines as strings (labels for the points)
  var  CAtoAB =()=>((angle(CA,AB)*180/Math.PI)|0)+'&deg;', 
       ABtoBC =()=>((angle(AB,-BC)*180/Math.PI)|0)+'&deg;',
       CAtoBC =()=>((angle(CA,BC)*180/Math.PI)|0)+'&deg;';

  // Distance between point and line.
  var BtoCA  =()=>dist_pl(B,CA).toFixed(3);

  // Graph the triangle, its angles and side lengths.
  document.body.appendChild(this.graph([
    0xffcccc, [A,B,C],                              // render the triangle
    0xff4444, AB, AtoB, BC, BtoC, CA, CtoA,         // render edges and lengths.
    0x444444, A, CAtoAB, B, ABtoBC, C, CAtoBC,      // render verts and angles
    0x8888ff, [B,()=>(CA<<B)*CA], BtoCA, 
  ],{grid:true,animate:true}));
});
</SCRIPT></BODY>